// $Id: server.h 113 2011-11-28 17:07:05Z cedric.shih@gmail.com $
/*
 * Copyright 2011 Cedric Shih (cedric dot shih at gmail dot com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef NIOHTTP_SERVER_H_
#define NIOHTTP_SERVER_H_

#include <sys/queue.h>
#include <niohttp/transport.h>

struct event_base;

struct niohttpd *niohttpd_new(struct event_base *evbase);

void niohttpd_free(struct niohttpd *server);

int niohttpd_bind(struct niohttpd *server,
		const char *address, unsigned short port);

struct niohttp_transport;

int niohttpd_add_transport(struct niohttpd *server,
		const char *type, struct niohttp_transport *transporter);

struct niohttp_media;

struct niohttp_headers;

typedef int (*niohttp_media_describe_cb)(struct niohttp_media *media,
		struct niohttp_headers *headers, void *cbarg);

int niohttpd_add_media(struct niohttpd *server, const char *name,
		niohttp_media_describe_cb describe, void *cbarg);

int niohttpd_remove_media(struct niohttpd *server, const char *name);

struct niohttp_track;

typedef int (*niohttp_track_cb)(struct niohttp_track *track, void *cbarg);

typedef int (*niohttp_track_describe_cb)(struct niohttp_track *track,
		struct niohttp_headers *headers, void *cbarg);

typedef void (*niohttp_track_finalize_cb)(
		struct niohttp_track *track, void *cbarg);

int niohttpd_add_track(struct niohttpd *server, const char *media_name,
		const char *name, const char *type,
		niohttp_track_describe_cb describe,
		niohttp_track_cb setup, niohttp_track_cb teardown,
		niohttp_track_cb refresh, niohttp_track_finalize_cb finalize,
		void *cbarg);

int niohttpd_remove_track(struct niohttpd *server, struct niohttp_track *track);

int niohttp_track_push(struct niohttp_track *track, struct timeval *timestamp,
		struct zcbuffer *buffer);

struct niohttp_session_item {
	TAILQ_ENTRY(niohttp_session_item) next;
};

TAILQ_HEAD(niohttp_session_list, niohttp_session_item);

struct niohttpd;

struct niohttp_session_list *niohttp_sessions(struct niohttpd *server);

#endif /* NIOHTTP_SERVER_H_ */
